package com.bright.hxj.qchz.service.impl;

import com.bright.hxj.qchz.mapper.CommonMapper;
import com.bright.hxj.qchz.pojo.po.Dist;
import com.bright.hxj.qchz.pojo.po.Zt;
import com.bright.hxj.qchz.service.DistManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Author hxj
 * @Date 2025/1/6 14:34
 * @Description
 */
@Component
@RequiredArgsConstructor
public class DistManagerImpl implements DistManager {

    private final CommonMapper commonMapper;
    private final ObjectMapper objectMapper;

    @Override
    public Zt getZtReturnObj(String ztId) {
        Zt zt = null;
        List<Map<String, Object>> maps = commonMapper.selectData("zt", "id, ztId, ztName, ztJc, distNo, distName", Collections.singletonMap("ztId", ztId), null);
        if (maps.size() > 0) {
            zt = objectMapper.convertValue(maps.get(0), Zt.class);
        }
        return zt;
    }

    @Override
    public Dist getDistByObj(String distNo) {
        Dist dist = null;
        List<Map<String, Object>> maps = commonMapper.selectData("dist", "id, distNo, distName, parentDistNo, parentDistName", Collections.singletonMap("distNo", distNo), null);
        if (maps.size() > 0) {
            dist = objectMapper.convertValue(maps.get(0), Dist.class);
        }
        return dist;
    }
}
